package com.dailyblue.example.project.category.controller;

import com.dailyblue.example.project.bookstore.commons.util.JsonResult;
import com.dailyblue.example.project.category.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService service;

    @GetMapping("/id/{id}")
    public JsonResult find(@PathVariable String id) {
        /*if (id.equals("1521444078676357121")) {
            throw new RuntimeException();
        }*/
        return service.findCategoryById(id);
    }

    @GetMapping
    public JsonResult find() {
        return service.findCategory();
    }

    @GetMapping("/{limit}")
    public JsonResult find(@PathVariable int limit) {
        return service.findCategoryLimit(limit);
    }
}
